<template>
    <div>
        <el-button size="large" type="danger" @click="dialogFormVisible = true"><i class="el-icon-shopping-cart-2"></i>Add To Cart</el-button>
        <el-dialog title="选择数量" :visible.sync="dialogFormVisible">
            <el-input-number v-model="number" :min="1" :max="10"></el-input-number>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="addToCart">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import router from '@/router';
export default {
    name: 'addTocart',
    props:{
        itemid: [String]
    },
    data() {
        return {
            number: 1,
            dialogFormVisible: false
        }
    },
    methods:{
        addToCart(){
            this.dialogFormVisible = false;
            let args = {
                itemid: this.itemid,
                quantity: this.number
            }
            this.$Axios({
                method: 'post',
                url: 'order/add-cart',
                data: args,
            }).then(res=>{
                router.push("/cart");
            }).catch(error=>{
                this.$message.error("其他服务器错误"+error);
            })
        }
    }
}
</script>